package web;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/logOut")
public class LogOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies();
        System.out.println("test");
        for(Cookie cookie:cookies){
            System.out.println(cookie);
            String name = cookie.getName();
            if("PWM".equals(name) ||"UNM".equals(name) ||"uid".equals(name)){
                cookie.setMaxAge(0);
                response.addCookie(cookie);
            }
        }
        //退出完成后转跳到首页
        request.getRequestDispatcher("login.html").forward(request,response);
    }
}
